<?php
function gennerstringquacode($length = 12) {
    $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $allChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $randomString = '';
    $randomString .= $letters[rand(0, strlen($letters) - 1)];
    for ($i = 1; $i < $length; $i++) {
        $randomString .= $allChars[rand(0, strlen($allChars) - 1)];
    }
    return $randomString;
}
define('ROOT_DIR', $_SERVER['DOCUMENT_ROOT'].'/');
$quacode = gennerstringquacode();
$path = ROOT_DIR.'setting.php';
$settingsContent = file_get_contents($path);
$bklogins = $_GET['bklogin'];
$redis_ip = $_GET['redis_ip'];
$redis_port = $_GET['redis_port'];
$redis_password = $_GET['redis_password'];
$newSettingredisarray = <<<EOT
\$redis_pz  = array(
    "host"     => "$redis_ip",
    "port"     => $redis_port,
    "password" => "$redis_password",
);
EOT;
$newSettingMailArray = <<<EOT
\$website_array = array( 
    'admin' => '$bklogins',
    'quascode'=>'$quacode',
    'notlogined'=> 5,
    'notlogined2'=>5
);
EOT;
$pattern = '/\$website_array\s*=\s*array\s*\(\s*[^;]*\s*\);/s';
$replacement = $newSettingMailArray;
$updatedSettingsContent = preg_replace($pattern, $replacement, $settingsContent);
file_put_contents($path, $updatedSettingsContent);
$pattern = '/\$redis_pz\s*=\s*array\s*\(\s*[^;]*\s*\);/s';
$replacement = $newSettingredisarray;
$updatedSettingsContent = preg_replace($pattern, $replacement, $settingsContent);
file_put_contents($path, $updatedSettingsContent);
 file_put_contents($_SERVER['DOCUMENT_ROOT'].'/install.lock','install lock file');
 header('Location: /');